package com.kaifamiao.month04.day21.homework;

import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeMap;

public class Count {

    // 输入一个字符串，统计字符串中每个字符出现的次数.最后输出结果
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        char[] chars = str.toCharArray();
//        TreeMap<Character, Integer> map = new TreeMap<>();
        HashMap<Character, Integer> map = new HashMap<>();
        for (char c : chars) {
            if (!map.containsKey(c)) {
                map.put(c, 1);
            } else {
                map.put(c,  map.get(c) + 1);
            }
        }
        System.out.println(map);

        TreeMap<Character, Integer> hashMap = new TreeMap<>();
        for (char a : chars) {
            hashMap.merge(a, 1, Integer::sum);
        }

        TreeMap<Character, Integer> hashMap1 = new TreeMap<>();
        for (char a : chars) {
            if (hashMap1.get(a) == null) {
                hashMap1.put(a, 1);
            } else {
                hashMap1.put(a,hashMap1.get(a) + 1);
            }
        }

        System.out.println(hashMap);

    }

}
